package com.example.hongyu.avtt.ui.activity;

import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import androidx.viewpager.widget.PagerAdapter;
import androidx.viewpager.widget.ViewPager;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.example.hongyu.avtt.R;
import com.example.hongyu.avtt.event.Event;
import com.example.hongyu.avtt.ui.base.BaseActivity;
import com.example.hongyu.avtt.ui.widget.ZoomImageView;

import butterknife.BindView;

public class PictureShowActivity extends BaseActivity {
    @BindView(R.id.viewpager)
    ViewPager viewPager;
    String name="";
    String url="";
    private ImageView[] imageViewArray;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

    }

    @Override
    protected void initActivityData() {
        mBundle=getBundle();
        url=mBundle.getString("PLAYURL");
        name= mBundle.getString("PLAYNAME");
        String[] images = {url};
        imageViewArray = new ImageView[images.length];
        viewPager.setAdapter(new PagerAdapter() {

            @Override
            public Object instantiateItem(ViewGroup container, int position) {
                ZoomImageView scaleImageView = new ZoomImageView(getApplicationContext());
                Glide.with(PictureShowActivity.this)
                        .load(url)
                        .diskCacheStrategy(DiskCacheStrategy.SOURCE )
                        .crossFade().into(scaleImageView);
                container.addView(scaleImageView);
                imageViewArray[position] = scaleImageView;
                return scaleImageView;
            }

            @Override
            public void destroyItem(ViewGroup container, int position, Object object) {
                container.removeView(imageViewArray[position]);
            }

            @Override
            public boolean isViewFromObject(View arg0, Object arg1) {
                return arg0==arg1;
            }

            @Override
            public int getCount() {
                return imageViewArray.length;
            }
        });

    }

    @Override
    protected void initContentView() {

    }

    @Override
    protected int getContentView() {
        return R.layout.activity_picture_show;
    }

    @Override
    protected void onEventProcess(Event event) {

    }
}